package com.atguigu.lease.web.admin.controller.attr;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
    前段访问后端接口出现404：
        1、查看后端是否有接口 映射该请求

            http://localhost:5174/admin/term/list --> http://localhost:8080/admin/term/list
            请求方式 ， 必须的参数列表
       2、组件注解
       3、启动类是否可以扫描到Controller
 */
@RestController
@RequestMapping("/admin/term")
@Tag(name = "租期管理模块")
public class LeaseTermController {
    @Resource
    LeaseTermService leaseTermService;

    @Operation(summary = "查询所有租期")
    @GetMapping("list")
    public Result<List<LeaseTerm>> list() {
        return Result.ok(leaseTermService.list());
    }

    //saveOrUpdate
    @Operation(summary = "新增或更新租期")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseTerm term) {
        return Result.build(leaseTermService.saveOrUpdateTerm(term));
    }

    @Operation(summary = "根据id删除租期")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam Long id) {
        return Result.build(leaseTermService.removeById(id));

    }

}
